package tianwang.utils.segment;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import tianwang.utils.stanford.StanfordUtils;
import edu.stanford.nlp.ling.Word;
import edu.stanford.nlp.process.DocumentPreprocessor;

public class WordSegmentorStanfordImpl implements WordSegmentor {
	
	public ArrayList<String> segregate(String sentence) {
		DocumentPreprocessor documentPreprocessor  = StanfordUtils.getDocumentPreprocessor();
//		String regex = "^[\\w']\\w+";
		String regex = "[a-zA-Z]+";
		Pattern pattern = Pattern.compile(regex);
		List<Word> list = documentPreprocessor.getWordsFromString(sentence);
		ArrayList<String> out = new ArrayList<String>();
		for ( Iterator<Word> itr = list.iterator(); itr.hasNext();){
			Word word = itr.next();
			Matcher matcher = pattern.matcher(word.value());
			if ( matcher.matches()){
				out.add(word.value());
			}			
		}
	    return out;
	}
}
